package com.example.demo.config;

import javax.annotation.Resource;

import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

import com.example.demo.entity.MyUser;
import com.example.demo.repository.MyUserRepository;

@Component
public class MyUserDetailServise implements UserDetailsService{

	@Resource
	private PasswordEncoder passwordEncoder;
	@Resource
	private MyUserRepository myUserRepository;
	@Override
	public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
		MyUser myUser = myUserRepository.findByUName(userName);
		
		return new User(userName, myUser.getPassword(), AuthorityUtils.commaSeparatedStringToAuthorityList(myUser.getAuth()));
		
	}

}
